<!-- 添加商品分类页面 -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <title>添加商品分类页面</title>
</head>
<?php
include_once("inc.php");
include_once("base.php");
$tb_name = "category";
if ($_REQUEST["id"]) {
	$rs = db_get_row("select * from $tb_name where id=". $_REQUEST["id"]);
}
if ($_POST){
	if ($_REQUEST["id"]) {
		if($_POST["title"]!=$_POST["title1"]){
			$row1 = db_get_row("select * from $tb_name where title='". $_POST["title"] ."'");
			if ($row1["id"]) {
				goBakMsg("名称重复，请重新填写");
				die;
			}
		}
	} else {
		$row1 = db_get_row("select * from $tb_name where title='". $_POST["title"] ."'");
		if ($row1["id"]) {
			goBakMsg("名称重复，请重新填写");
			die;
		}
	}
	$data = array();
	$data["title"] = "'".$_POST["title"]."'";
	$data['pid']=1;
	// if($_POST["pid"]){$data["pid"] = "'".$_POST["pid"]."'";}
	if ($_REQUEST["id"]) {
		db_mdf($tb_name,$data,$_REQUEST["id"]);
	} else {
		db_add($tb_name,$data);
	}
	urlMsg("22操作成功", $tb_name."_list.php");
	die;
}
?>
<script>
function checkadd()
{
	if (document.add.title.value=='')
	{
	alert('名称不能为空');
	document.add.title.focus;
	return false
	}
}
</script>
<body>
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td width="17" rowspan="2" valign="top" bgcolor="#FFFFFF"></td>
			<td valign="top">
				<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0">
					<tr bgcolor="#FFFFFF">
						<td height="31">
							<div class="title">添加/修改操作</div>
						</td>
					</tr>
				</table>
			</td>
			<td width="16" rowspan="2" bgcolor="#FFFFFF"></td>
		</tr>
		<tr>
			<td valign="top" bgcolor="#F7F8F9">
				<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
					<tr>
						<td colspan="4" height="10"></td>
					</tr>
					<tr>
						<td width="1%">&nbsp;</td>
						<td width="96%">
							<table width="100%">
								<tr>
									<td colspan="2">
										<form name="add" method="post" action="?" onSubmit="return checkadd()">
											<input type="hidden" name="id" value="<?php echo $rs["id"];?>" />
											<input type="hidden" name="title1" value="<?php echo $rs["title"];?>" />
											<input type="hidden" name="pid" value="<?php echo $_REQUEST["pid"];?>">
											<table width="100%" class="cont">
												<tr>
													<td width="40%" align="right">
														<span class="red">*</span> 名称：
													</td>
													<td width="">
														<input name="title" type="text" class="text" size="30" value="<?php echo $rs["title"];?>">
													</td>
												</tr>
												<tr>
													<td align="right">&nbsp;</td>
													<td>
														<input class="btn" type="submit" value="提交" /> 
														<input name="button" type="button" class="btn" onClick="javascript:history.back();" value="返回">
													</td>
												</tr>
											</table>
										</form>
									</td>
								</tr>
							</table>
						</td>
						<td width="1%">&nbsp;</td>
					</tr>
					<tr><td height="20"></td></tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>
